<?php
	require_once('../inc/fen_fns.php');
	
	sec_session_start();
	$pid = substr($_GET['pid'],2);

	$query = $_DB->Query("SELECT
		fen_publications.id as publication_id,
		fen_publications.member_id as publication_member_id,
		fen_publications.yayin_tipi,
		fen_publications.yayin_turu,
		fen_publications.eser_adi,
		fen_publications.dergi_adi,
		fen_publications.volume,
		fen_publications.issue,
		fen_publications.sayfa,
		fen_publications.yayinevi_adi,
		fen_publications.doi_no,
		fen_publications.yayin_yili,
		fen_publications.yazar_sayisi,
		fen_publications.indeks_turu,
		fen_publications.indeks_alan,
		fen_publications.sinif,
		fen_publications.kitap_adi,
		fen_publications.editor_adi,
		fen_publications.isbn_no,
		fen_faculty.faculty_name,
		fen_members.name, fen_members.surname, fen_members.titr
		from fen_publications, fen_members, fen_faculty
		WHERE
		fen_publications.member_id = fen_members.id and
		fen_publications.id = '$pid' and
		fen_members.username = '".$_SESSION['username']."' and fen_members.faculty_id = fen_faculty.id");
		
		$count = $_DB->GetResultNumber($query);

		$titr = $_DB->GetResultValue($query, "0", "titr");
		$name = $_DB->GetResultValue($query, "0", "name");
		$surname = $_DB->GetResultValue($query, "0", "surname");
		$member_id = $_DB->GetResultValue($query, "0", "publication_member_id");
		$yayin_tipi = $_DB->GetResultValue($query, "0", "yayin_tipi");
		$yayin_turu = $_DB->GetResultValue($query, "0", "yayin_turu");
		$eser_adi = $_DB->GetResultValue($query, "0", "eser_adi");
		$dergi_adi = $_DB->GetResultValue($query, "0", "dergi_adi");
		$volume = $_DB->GetResultValue($query, "0", "volume");
		$issue = $_DB->GetResultValue($query, "0", "issue");
		$sayfa = $_DB->GetResultValue($query, "0", "sayfa");
		$yayinevi_adi = $_DB->GetResultValue($query, "0", "yayinevi_adi");
		$doi_no = $_DB->GetResultValue($query, "0", "doi_no");
		$yayin_yili = $_DB->GetResultValue($query, "0", "yayin_yili");
		$yazar_sayisi = $_DB->GetResultValue($query, "0", "yazar_sayisi");
		$indeks_turu = $_DB->GetResultValue($query, "0", "indeks_turu");
		$indeks_alan = $_DB->GetResultValue($query, "0", "indeks_alan");
		$alan = $_DB->GetResultValue($query, "0", "alan");
		$sinif = $_DB->GetResultValue($query, "0", "sinif");
		$kitap_adi = $_DB->GetResultValue($query, "0", "kitap_adi");
		$editor_adi = $_DB->GetResultValue($query, "0", "editor_adi");
		$isbn_no = $_DB->GetResultValue($query, "0", "isbn_no");
		$faculty_name = $_DB->GetResultValue($query, "0", "faculty_name");
				
		if ($sinif) {
			$sinif = "(".$sinif.")";
		}

		if ($indeks_alan) {
			$indeks_alan = " (".$indeks_alan.")";
		}
		
		if ($doi_no) {
			$doi = "<br>DOI: ".$doi_no;
		} else {
			$doi = "";
		}
		
		$dergi_adi = $dergi_adi."<br>Volume: ".$volume." Issue: ".$issue." (".$yayin_yili.") p: ".$sayfa." ".$doi;
		
		if ($yayin_tipi == 'Kitap') {
			$dergi_adi = $eser_adi."<br>ISBN: ".$isbn_no;
			$yayinevi_adi = $_DB->GetResultValue($query, "0", "yayinevi_adi");
		}
		
		if ($yayin_tipi == 'Kitap Bölümü') {
			$dergi_adi = $kitap_adi."<br>Editör: ".$editor_adi."<br>ISBN: ".$isbn_no;
			$yayinevi_adi = $_DB->GetResultValue($query, "0", "yayinevi_adi");
		}
		
		if (login_check($mysqli, '>', '10') == true) {
		
		
//============================================================+
// File name   : example_002.php
// Begin       : 2008-03-04
// Last Update : 2010-08-08
//
// Description : Example 002 for TCPDF class
//               Removing Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               Manor Coach House, Church Hill
//               Aldershot, Hants, GU12 4RQ
//               UK
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Removing Header and Footer
 * @author Nicola Asuni
 * @since 2008-03-04
 */

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

class MYPDF extends TCPDF {
	
	public function MultiRow($left, $right) {
		// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
	
		$page_start = $this->getPage();
		$y_start = $this->GetY();
	
		// write the left cell
		$this->MultiCell(40, 0, $left, 1, 'R', 1, 2, '', '', true, 0);
	
		$page_end_1 = $this->getPage();
		$y_end_1 = $this->GetY();
	
		$this->setPage($page_start);
	
		// write the right cell
		$this->MultiCell(0, 0, $right, 1, 'J', 0, 1, $this->GetX() ,$y_start, true, 0);
	
		$page_end_2 = $this->getPage();
		$y_end_2 = $this->GetY();
	
		// set the new row position by case
		if (max($page_end_1,$page_end_2) == $page_start) {
			$ynew = max($y_end_1, $y_end_2);
		} elseif ($page_end_1 == $page_end_2) {
			$ynew = max($y_end_1, $y_end_2);
		} elseif ($page_end_1 > $page_end_2) {
			$ynew = $y_end_1;
		} else {
			$ynew = $y_end_2;
		}
	
		$this->setPage(max($page_end_1,$page_end_2));
		$this->SetXY($this->GetX(),$ynew);
	}

}

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Onur Mendi');
$pdf->SetTitle('BAHÇEŞEHİR ÜNİVERSİTESİ');
$pdf->SetSubject('Bilimsel Yayınları Teşvik Müracaat Formu');
$pdf->SetKeywords('Created by Onur Mendi onur@mendi.co');

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('dejavusans', 'B', 9);

// add a page
$pdf->AddPage();

// set some text to print
$txt = <<<EOD
BAHÇEŞEHİR ÜNİVERSİTESİ
Bilimsel Yayınları Teşvik Müracaat Formu
EOD;

// print a block of text using Write()
$pdf->Write($h=5, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
$pdf->SetFont('dejavusans', 'R', 9);


$tbl = <<<EOD
<br><br><br><table STYLE="line-height:150%" cellspacing="0" cellpadding="5" border="1">
    <tr>
        <td width="20%">Yazar Ünvanı</td>
        <td width="80%">$titr</td>
    </tr>
    <tr>
        <td width="20%">Yazar Adı</td>
        <td width="80%">$name $surname</td>
    </tr>
    <tr>
       <td width="20%">Fakülte</td>
       <td width="80%">$faculty_name</td>
    </tr>
	<tr>
       <td width="20%">Eserin Adı<br></td>
       <td width="80%">$eser_adi</td>
    </tr>
	<tr>
       <td width="20%">Dergi/Kitap Adı<br></td>
       <td width="80%">$dergi_adi</td>
    </tr>
	<tr>
       <td width="20%">Yayınevi Adı</td>
       <td width="80%">$yayinevi_adi</td>
    </tr>
	<tr>
       <td width="20%">Yayın Yılı</td>
       <td width="80%">$yayin_yili</td>
    </tr>
	<tr>
       <td width="20%">Yazar Sayısı</td>
       <td width="80%">$yazar_sayisi</td>
    </tr>
	<tr>
       <td width="20%">Yayın Türü</td>
       <td width="80%">$yayin_turu</td>
    </tr>
	<tr>
       <td width="20%">Yayın Tipi</td>
       <td width="80%">$yayin_tipi</td>
    </tr>
	<tr>
       <td width="20%">Endeks</td>
       <td width="80%">$indeks_turu $indeks_alan $sinif</td>
    </tr>	
	<tr>
       <td width="20%">Onay Karar No<br></td>
       <td width="80%"></td>
    </tr>	
</table>
EOD;

$pdf->writeHTML($tbl, true, false, false, false, '');
$date = date("d.m.Y");

$pdf->SetFont('dejavusans', 'R', 9);
$tbl = <<<EOD
<table cellspacing="0" cellpadding="5" border="0">
    <tr>
        <td width="69%"><br><br>Başvuru sahibinin imzası ve tarih</td>
        <td width="31%"><br><br>Dekan/Müdür imzası ve tarih</td>
    </tr>
	<tr>
        <td width="69%"><br><b>$titr $name $surname</b></td>
        <td width="31%"><br><b>Prof. Dr. Nuri KURUOĞLU</b></td>
    </tr>
	<tr>
        <td width="69%"><br><br>Tarih: $date<br><br>İmza:</td>
        <td width="31%"><br><br>Tarih: <br><br>İmza:</td>
    </tr>

</table>
EOD;

$pdf->writeHTML($tbl, true, false, false, false, '');
$outputfilename = "Bilimsel_Yayin_".$pid;

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output($outputfilename, 'D');

//============================================================+
// END OF FILE                                                
//============================================================+

} else {
	header('Location: ./index.php?error=2');
}